package com.nanhang.controller;

import com.nanhang.entity.TbSpecificationOption;
import com.nanhang.service.TbSpecificationOptionService;
import com.nanhang.util.PageResult;
import com.nanhang.util.R;
import com.nanhang.vo.TbSpecificationOptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tbspecificationOption")
@CrossOrigin
public class TbSpecificationOptionController {
    @Autowired
    private TbSpecificationOptionService tbSpecificationOptionService;
    @PostMapping("/search")
    public PageResult<TbSpecificationOption> search(@RequestParam("page") Integer page,
                                                    @RequestParam("pageSize") Integer pageSize,
                                                    @RequestBody(required = false)TbSpecificationOptionVO tbSpecificationOptionVo){
        return tbSpecificationOptionService.search(page,pageSize,tbSpecificationOptionVo);
    }

    // 4. 保存规格
    @PostMapping("/save")
    public R save(@RequestBody TbSpecificationOption tbSpecificationOption){
        return tbSpecificationOptionService.save(tbSpecificationOption) ? R.ok().message("规格选项添加成功！") : R.error().message("规格选项添加失败！");
    }
}
